import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

# 读取数据
df = pd.read_csv('yiche_brands_sales.csv')

# 设置中文字体
font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)

# 数据清洗
df.dropna(subset=['sales'], inplace=True)

# 按销量排序
df = df.sort_values(by='sales', ascending=False)

# 品牌销量分析
plt.figure(figsize=(12, 6))
plt.bar(df['brand'], df['sales'], color='skyblue')
plt.title('品牌销量分析', fontproperties=font)
plt.xlabel('品牌', fontproperties=font)
plt.ylabel('销量', fontproperties=font)
plt.xticks(rotation=90, fontproperties=font)
plt.tight_layout()
plt.savefig('品牌销量分析.png')
plt.show()
